<?
include_once '/var/www/html/new/com.inc.php';
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$s = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));
$aid=$_SESSION['sid'];
$lid=$_REQUEST['type']? $_REQUEST['type'] : '';
$btime=$_REQUEST['bt']? $_REQUEST['bt'] : date('Y-m-d',strtotime("-30days"));
$etime=$_REQUEST['et']? $_REQUEST['et'] :date('Y-m-d');
$bt= $btime .' 00:00:00';
$et = $etime .' 23:59:59'; 
$lid_arr=array();
//获取已完成订单的lid和title
   $x_ob1 = simplexml_load_string($s -> Order_Globle_Search( 
     "","$aid", "", "", "", "", "", "", "", "",
     "$bt", "$et", "", "", "", "1", "", "", "1", "1",
     "0", "1000", "0", "0","","0","0", "0","","",
      "", "", "", "", ""));
	
	  foreach($x_ob1->Rec as $key1=>$val1)
	  {if($val1->UUpmode==3)
	  $lid_arr[(string)$val1->UUlid]=$val1->UUltitle;
	  $lid_arr2[(string)$val1->UUltitle]=$val1->UUtnum;
	  
	  }
	 
	  $x_ob2 = simplexml_load_string($s -> Order_Globle_Search( 
     "","", "", "", "", "", "", "", "", "",
     "$bt", "$et", "", "", "", "1", "", "", "1", "1",
     "0", "1000", "0", "0","","0","0", "0","","",
      "$aid", "", "", "", ""));
	 
	  foreach($x_ob2->Rec as $key2=>$val2)
	  {
	  $lid_arr[ (string)$val2->UUlid ]=$val2->UUltitle;
	  //$lid_arr2[(string)$val2->UUltitle]=$val2-UUtnum;
	  }
	//print_r($lid_arr);
	  $lid_arr=array_unique($lid_arr);
	 // print_r($lid_arr2);
	 // $lid_arr2=array_unique($lid_arr2);
	  
	  //sort($lid_arr2);
	 // echo "<br/>";
	 // print_r($lid_arr2);
	  //获取自供自销的地区、票数、和总钱数
	  $x = simplexml_load_string($s -> Order_Globle_Search( 
     "","$aid", "$lid", "", "", "", "", "", "", "",
     "$bt", "$et", "", "", "", "1", "", "", "1", "1",
     "0", "1000", "0", "0","","0","0", "0","","",
      "", "", "", "", ""));
	
	  
	 foreach($x->Rec as $k=>$v)
	  { 
	    $vb=(int)$v->UUpmode;
		 if($vb==3)
	     
		{$selfmobile=(string)$v->UUordertel;
	     $selforigin=(string)checkMobilePlace($selfmobile);
	     $selfarea=substr($selforigin,0,6);
	     //$d['origin']=$or;
	     $totalmoney+=(int)$v->UUtotalmoney/100;
		 $selftnum+=(int)$v->UUtnum;
		// print_r($d);
	     //$d['tnum']=(int)$v->UUtnum;
	     //$data[]=$d;
		}	 
	  }
//获取购买者地区、票数、和总钱数
$r=$s->Order_Globle_Search("","", "$lid", "", "", "", "", "", "", "",
     "$bt", "$et", "", "", "", "1", "", "", "1", "1",
     "0", "1000", "0", "0","","0","0", "0","","",
      "$aid", "", "", "", "");
	  
$obj=simplexml_load_string($r);
 //print_r($obj);
foreach($obj as $key=>$val){
	$mobile=(string)$val->UUordertel;
	$origin=(string)checkMobilePlace($mobile);
	$buyarea=substr($origin,0,6);
	$tikNum=$val->UUtnum;
	//取销售价乘以票数，数据更可靠
	if($val->UUaids_price!=0)
	{$reamoney=$val->UUaids_price;
	$remoney=explode(',',$reamoney);
	$rmoney=array_pop($remoney);
	$money=$rmoney*$tikNum;
	$tolmoney=$money/100;
	}
	else
	{$tolmoney=$val->UUtotalmoney/100;}
	
	$areadata[]=$buyarea;
	$datam[$buyarea]+=$tolmoney;
	$datat[$buyarea]+=$tikNum;
	//echo $tolmoney;
}
//print_r($datam);echo "money";
//echo "<br/>";
//print_r($datat);echo "num";
//只有自供自销的产品
 $datam[$selfarea]+=$totalmoney;
  $datat[$selfarea]+=$selftnum;

//print_r($datam);


arsort($datam);
foreach($datam as $key=>$v)

{if($key!='')
{$str.="{name:'".$key."', value:".$v."},";}
}
$str=substr($str,0,-1);
//echo $str;
//echo "<br/>";
foreach($datam as $key=>$v)
{  if($key!='')
{$strb.="{name:'".$key."', value:".$v."},"; } 
}   
$strb=substr($strb,0,-1);
//echo $strb;

function checkMobilePlace($mobilephone){
$url = "http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=".$mobilephone."&t=".time();
$content = file_get_contents($url);
$p = substr($content, 56, 4);
$mo = substr($content, 81, 4);
return $str = conv2utf8($p).conv2utf8($mo);
}
function conv2utf8($text){
return mb_convert_encoding($text,'UTF-8','ASCII,GB2312,GB18030,GBK,UTF-8');
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="ECharts">
    <meta name="author" content="kener.linfeng@gmail.com">
    <title>ECharts · Example</title>

    <link rel="shortcut icon" href="../asset/ico/favicon.png">

    <link href="../asset/css/font-awesome.min.css" rel="stylesheet">
    <link href="../asset/css/bootstrap.css" rel="stylesheet">
    <link href="../asset/css/carousel.css" rel="stylesheet">
    <link href="../asset/css/echartsHome.css" rel="stylesheet">
	<script language="javascript" src="http://www.12301.cc/js/jquery-1.8.0.min.js"></script>
    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <script src="./www/js/echarts.js"></script>
   <script src="../asset/js/codemirror.js"></script>
  <!--    <script src="../asset/js/javascript.js"></script> -->

    <link href="../asset/css/codemirror.css" rel="stylesheet">
    <link href="../asset/css/monokai.css" rel="stylesheet">
	<script src="http://www.12301.cc/js/select2.js"></script>
	<script src="http://www.12301.cc/js/WdatePicker.js"></script>

	<link rel="stylesheet" type="text/css" href="http://www.12301.cc/css/select2.css">

</head>

<body>
    <form action="" method="post"  name="form" >
		<select id="bindList" class="selectcss" name="type">
			 <?
               if($lid_arr){
			    foreach($lid_arr as $lid=>$v){ 
                ?>
					
	           <option value="<?=$lid?>" <?if($_REQUEST['type']==$lid)echo 'selected="selected"'?>><?=$v?></option>
	           <?}}else{?>
	           <option value="">请选择景区</option>
	           <?}?>
		</select>
		<span class="lt">活动时间：</span>
			<input type="text" data-t="bt" id="txtStartTime" value="<?=$_REQUEST['bt']?>" name="bt" data-msg="请选择时间段" class="textInp w175 alliNameInp" autocomplete="off"/> 至
			<input type="text" data-t="et" id="txtEndTime" value="<?=$_REQUEST['et']?>"  name="et" data-msg="请选择时间段" class="textInp w175 alliNameInp" autocomplete="off"/>
	
	<input type="submit" value="提交">
	</form>
    <div class="container-fluid">
        <div class="row-fluid example">
            <div id="sidebar-code">
                <div class="well sidebar-nav" style="display:none">
                    <div class="nav-header"><a href="#" onclick="autoResize()" class="glyphicon glyphicon-resize-full" id ="icon-resize" ></a>option</div>
                    <textarea id="code" name="code" >
option = {
    title : {
        text: '2011全国GDP（亿元）',
        subtext: '数据来自国家统计局'
    },
    tooltip : {
        trigger: 'item'
    },
    legend: {
        x:'right',
        selectedMode:false,
        data:[]
    },
    dataRange: {
        orient: 'horizontal',
        min: 0,
        max: 55000,
        text:['高','低'],           // 文本，默认为数值文本
        splitNumber:0
    },
    toolbox: {
        show : true,
        orient: 'vertical',
        x:'right',
        y:'center',
        feature : {
            mark : {show: true},
            dataView : {show: true, readOnly: false}
        }
    },
    series : [
        {
            name: '2011全国GDP分布',
            type: 'map',
            mapType: 'china',
            mapLocation: {
                x: 'left'
            },
            selectedMode : 'multiple',
            itemStyle:{
                normal:{label:{show:true}},
                emphasis:{label:{show:true}}
            },
            data:[
                <? echo $str?>
            ]
        },
        {
            name:'2011全国GDP对比',
            type:'pie',
            roseType : 'area',
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            center: [document.getElementById('main').offsetWidth - 250, 225],
            radius: [30, 120],
            data:[
              <? echo $strb ?>
            ]
        }
    ],
    animation: false
};
var ecConfig = require('echarts/config');
myChart.on(ecConfig.EVENT.MAP_SELECTED, function (param){
    var selected = param.selected;
    var mapSeries = option.series[0];
    var data = [];
    var legendData = [];
    var name = "2011全国GDP分布";
    for (var p = 0, len = mapSeries.data.length; p < len; p++) {
        name = mapSeries.data[p].name;
        //mapSeries.data[p].selected = selected[name];
        if (selected[name]) {
            data.push({
                name: name,
                value: mapSeries.data[p].value
            });
            legendData.push(name);
        }
    }
    option.legend.data = legendData;
    option.series[1].data = data;
    myChart.setOption(option, true);
})
                    </textarea>
              </div><!--/.well -->
            </div><!--/span-->
            <div id="graphic" class="col-md-8">
                <div id="main" class="main"></div>
                <div>
                    <button type="button" class="btn btn-sm btn-success" onclick="refresh(true)">刷 新</button>
                    <span class="text-primary">切换主题</span>
                    <select id="theme-select"></select>

                    <span id='wrong-message' style="color:red"></span>
                </div>
            </div>
        </div>
        
        </div>

    <footer id="footer"></footer>
   
		<script>
		$("#bindList").select2({
				placeholder: "Select a State",
				allowClear: true
		});
		$("#txtStartTime").bind("click focus", function () {  
	
		   var endtimeTf = $dp.$('txtEndTime');             
		   WdatePicker({                            
			   maxDate: '#F{$dp.$D(\'txtEndTime\')}',      
			   dateFmt: "yyyy-MM-dd",              
			   onpicked: function () { endtimeTf.focus(); }          
				});         
		   });          
		   $("#txtEndTime").bind("click focus", function () {       
				WdatePicker({           
				   minDate: '#F{$dp.$D(\'txtStartTime\')}', 
				   dateFmt: "yyyy-MM-dd"       
			   });         
		   });
	</script>
    <script src="../asset/js/jquery.min.js"></script>
    <script src="../asset/js/echartsExample.js"></script>
</body>
</html>
